<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/3
 * Time: 0:19
 */

namespace app\common\lib;
use JPush\Client;

/**
 * 极光推送封装
 * Class Jpush
 * @package app\common\lib
 */
class Jpush
{
    /**
     * 推送信息
     * @param $title
     * @param int $newsId
     * @param string $type
     * @return bool
     */
    public static function push($title, $newsId = 0, $type = 'android'){
        try{
            $client = new Client('', '');
            $client->push()->setPlatform('all')
                ->addAllAudience()
                ->setNotificationAlert($title)
                ->androidNotification($title, array(
                    'title' => $title,
                    'extras' => array(
                        'id' => $newsId,
                    ),
                ))->send();
        }catch (\Exception $e){
            echo $e->getMessage();// test
            return false;
        }
        return true;
    }

}